Fired automatically when an object is instantiated.
Syntax |
|---|
|
Constructor [Parameter List] |
Parameters |
||
|---|---|---|
|
Parameter List |
Any (Optional) |
Optional list of parameters. |
Notes
When you create a new object, you will sometimes want to perform some sort of initialization on the object. The constructor is a mechanism for doing this. A class's constructor is the method that will be executed automatically when an instance of the class is created.
You write a constructor for a custom class by creating a new method for the class and naming it "Constructor". The drop-down list for the Method name field suggests this name and the names of all other methods that can be overridden.
When you create a constructor for any subclass, the REALbasic Code Editor automatically inserts code that calls the constructor for its super class using the Super keyword. If there is more than one constructor, it inserts calls to all of them. This is because the subclass's constructor overrides its super class's constructor but the new subclass may not initialize itself correctly without a call to the super class's constructor. You can edit the inserted calls in the event that this assumption is incorrect.
See the chapter on custom classes in the Users Guide for more information on writing constructors.
See Also
Destructor method; Super keyword.